<?php
session_start();
include("load-settings.php");

if(!isset($_SESSION['user']))
	header("Location: login.php");

$user = $_SESSION['user'];
$result = mysql_query("SELECT * FROM user WHERE id = $user");
$row = mysql_fetch_array($result);
$username = $row['username'];
?>
<!doctype html>
<html>
<head>
  <meta charset="UTF-8" />
  <meta name="viewport" content="width=device-width, maximum-scale=1, initial-scale=1, user-scalable=0">

  <!-- Always force latest IE rendering engine or request Chrome Frame -->
  <meta content="IE=edge,chrome=1" http-equiv="X-UA-Compatible">
    <link rel="icon" href="http://www.veteranboosters.com/wp-content/uploads/2014/04/favicon4.png" type="image/x-icon"/>
    <link rel="shortcut icon" href="http://www.veteranboosters.com/wp-content/uploads/2014/04/favicon4.png" type="image/x-icon"/>
  <link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Open+Sans:400,600,800">

  <!-- Use title if it's in the page YAML frontmatter -->
  <title>Veteran Boosters Order Tracking</title>


  <!--[if lt IE 9]>
  <script src="../../javascripts/vendor/html5shiv.js" type="text/javascript"></script>
  <script src="../../javascripts/vendor/excanvas.js" type="text/javascript"></script>
  <![endif]-->
<link rel="stylesheet" href="css/bootstrap.min.css" />
<link rel="stylesheet" href="css/font-awesome.css" />
<link rel="stylesheet" href="css/fullcalendar.css" />
<link rel="stylesheet" href="css/jquery.jscrollpane.css" />	
<link rel="stylesheet" href="css/unicorn.css" />
  <!--<link href="stylesheets/application.css" media="screen" rel="stylesheet" type="text/css" />-->
  <script src="javascripts/application.js" type="text/javascript"></script>
</head>

<?php
	include("top.php");
?>

  <div class="container-fluid padded">
    <div class="row-fluid">

      <!-- Breadcrumb line -->

      <div id="breadcrumb">
	  <a href="/" title="" class="tip-bottom" data-original-title="Go to Home"><i class="fa fa-home"></i> Home</a>
	<a href="#">Members</a>
	<a href="#" class="current">Payouts  </a>
				
    </div>
    </div>
    </div>

    <div class="container-fluid padded">
<div class="row-fluid">
   <div class="col-lg-12">
      <div class="box">
         <div class="box-header">
            <span class="title">Orders under review</span>
         </div>
         <div class="box-content">
            <table class="table table-bordered table-striped table-hover">
               <thead>
                  <tr>
					 <th>ID</th>
                     <th>Details</th>
                     <th>Progress</th>
                     <th>Status</th>
					 <th>Payment</th>
                     <th>Actions</th>
                  </tr>
               </thead>
               <tbody>
			   <?php
					
						$result = mysql_query("SELECT * FROM booster_order WHERE active = 3 AND booster = ".$_SESSION['user']);

						if(mysql_num_rows($result) == 0)
						{
							echo "<tr><td colspan='4'>You don't have any orders under review.</td></tr>";
						}
						else
						{
							while($row = mysql_fetch_array($result))
							{
								$order = $row['order_record'];

								$subresult = mysql_query("SELECT * FROM order_record WHERE id = $order");
								$subrow = mysql_fetch_array($subresult);

								if($subrow['end_tier'] != null && $subrow['end_tier'] != "")
								{
									echo "<tr><td>".$subrow['start_tier']." ".$subrow['start_division']." - ".$subrow['end_tier']." ".$subrow['end_division']."</td>";

									echo "<td>".$row['wins']." wins</td>";

									if($row['active'] == 1)
									{
										echo "<td>Active</td>";
										
									}
									else if($row['active'] == 2)
									{
										echo "<td>Paused</td>";
										
									}
									else if($row['active'] == 3)
									{
										echo "<td>Admin reviewing</td>";

									}
									else if($row['active'] == 0)
										{
											echo "<td>Complete</td>";
											
										}
									$payment_result = mysql_query("SELECT SUM(amount) AS full_pay FROM payment WHERE identifier = '$username' AND booster_order = ".$subrow['id']) or die(mysql_error());
									$payment_row = mysql_fetch_array($payment_result);
									echo "<td>".$payment_row['full_pay']."</td>";
									echo "<td><a href='order.php?id=".$subrow['id']."' class='btn btn-success btn-xs'>Details</a></td>";
									echo "</tr>";
								}
								else
								{
									echo "<tr><td>".$subrow['number_of_wins']." wins at ".$subrow['start_tier']." ".$subrow['start_division']."</td>";

									echo "<td>".($row['wins']-$row['losses'])." of ".$subrow['number_of_wins']." wins</td>";

									if($row['active'] == 1)
									{
										echo "<td>Active</td>";
										
									}
									else if($row['active'] == 2)
									{
										echo "<td>Paused</td>";

									}
									else if($row['active'] == 3)
									{
										echo "<td>Admin reviewing</td>";
										
									}
									else if($row['active'] == 0)
										{
											echo "<td>Complete</td>";
											
										}
									$payment_result = mysql_query("SELECT SUM(amount) AS full_pay FROM payment WHERE identifier = '$username' AND booster_order = ".$subrow['id']) or die(mysql_error());
									$payment_row = mysql_fetch_array($payment_result);
									echo "<td>".$payment_row['full_pay']."</td>";
									echo "<td><a href='order.php?id=".$subrow['id']."' class='btn btn-success btn-xs'>Details</a></td>";
									echo "</tr>";
								}
							}
						}
				?>
			   </tbody>
            </table>
         </div>
      </div>
   </div>

  <div class="row-fluid">
   <div class="col-lg-12">
      <div class="box">
         <div class="box-header">
            <span class="title">Complete Orders</span>
         </div>
         <div class="box-content">
            <table class="table table-bordered table-striped table-hover">
               <thead>
                  <tr>
					 <th>ID</th>
                     <th>Details</th>
                     <th>Progress</th>
                     <th>Status</th>
					 <th>Payment</th>
                     <th>Actions</th>
                  </tr>
               </thead>
               <tbody>
			   <?php

						$result = mysql_query("SELECT * FROM booster_order WHERE active = 0 AND booster = ".$_SESSION['user']." GROUP BY order_record");

						if(mysql_num_rows($result) == 0)
						{
							echo "<tr><td colspan='4'>You don't have any complete orders.</td></tr>";
						}
						else
						{
							while($row = mysql_fetch_array($result))
							{
								$order = $row['order_record'];

								$subresult = mysql_query("SELECT * FROM order_record WHERE id = $order") or die(mysql_error());
								$subrow = mysql_fetch_array($subresult);

								$payment_result = mysql_query("SELECT * FROM payment WHERE identifier = '".$username."' AND booster_order = '".$subrow['id']."'") or die(mysql_error());


								if(mysql_num_rows($payment_result) != 0)
								{
									$payment_row = mysql_fetch_array($payment_result);

									echo "<tr><td>".$subrow['id']."</td>";

									if($subrow['end_tier'] != null && $subrow['end_tier'] != "")
									{
										echo "<td>".$subrow['start_tier']." ".$subrow['start_division']." - ".$subrow['end_tier']." ".$subrow['end_division']."</td>";

										echo "<td>".$row['wins']." wins</td>";

										if($row['active'] == 1)
										{
											echo "<td>Active</td>";
											
										}
										else if($row['active'] == 2)
										{
											echo "<td>Paused</td>";
											
										}
										else if($row['active'] == 3)
										{
											echo "<td>Admin reviewing</td>";
											
										}
										else if($row['active'] == 0)
										{
											echo "<td>Complete</td>";
											
										}

										$payment_result = mysql_query("SELECT SUM(amount) AS full_pay FROM payment WHERE identifier = '".$username."' AND booster_order = '".$subrow['id']."'") or die(mysql_error());
										$payment_row = mysql_fetch_array($payment_result);
										echo "<td>".$payment_row['full_pay']."</td>";
										echo "<td><a href='order.php?id=".$subrow['id']."' class='btn btn-success btn-xs'>Details</a></td>";
										echo "</tr>";
									}
									else
									{
										echo "<td>".$subrow['number_of_wins']." wins at ".$subrow['start_tier']." ".$subrow['start_division']."</td>";

										echo "<td>".($row['wins']-$row['losses'])." of ".$subrow['number_of_wins']." wins</td>";

										if($row['active'] == 1)
										{
											echo "<td>Active</td>";
											
										}
										else if($row['active'] == 2)
										{
											echo "<td>Paused</td>";

										}
										else if($row['active'] == 3)
										{
											echo "<td>Admin reviewing</td>";

										}
										else if($row['active'] == 0)
										{
											echo "<td>Complete</td>";

										}
										
										$payment_result = mysql_query("SELECT SUM(amount) AS full_pay FROM payment WHERE identifier = '".$username."' AND booster_order = '".$subrow['id']."'") or die(mysql_error());
										$payment_row = mysql_fetch_array($payment_result);
										echo "<td>".$payment_row['full_pay']."</td>";
										echo "<td><a href='order.php?id=".$subrow['id']."' class='btn btn-success btn-xs'>Details</a></td>";
										echo "</tr>";
									}
								}
							}
						}
			?>
			   </tbody>
            </table>
         </div>
      </div>
   </div>
</div>
    <!--
<div class="row-fluid">
   <div class="col-lg-12">
      <div class="box">
         <div class="box-header">
            <span class="title">Complete Duo Orders</span>
         </div>
         <div class="box-content">
            <table class="table table-bordered table-striped table-hover">
               <thead>
                  <tr>
					 <th>ID</th>
                     <th>Details</th>
                     <th>Progress</th>
                     <th>Status</th>
					 <th>Payment</th>
                     <th>Actions</th>
                  </tr>
               </thead>
               <tbody>
			   <?php
						$result = mysql_query("SELECT * FROM booster_duo WHERE active = 0 AND booster = ".$_SESSION['user']." GROUP BY duo_order");

						if(mysql_num_rows($result) == 0)
						{
							echo "<tr><td colspan='4'>You don't have any complete orders.</td></tr>";
						}
						else
						{
							while($row = mysql_fetch_array($result))
							{
								$order = $row['duo_order'];

								$subresult = mysql_query("SELECT * FROM duo_order WHERE id = $order") or die(mysql_error());
								$subrow = mysql_fetch_array($subresult);

								$payment_result = mysql_query("SELECT * FROM payment WHERE identifier = '".$username."' AND booster_order = '".$subrow['id']."'");

								if(mysql_num_rows($payment_result) != 0)
								{
									$payment_row = mysql_fetch_array($payment_result);

									echo "<tr><td>".$subrow['id']."</td>";

									if($subrow['number_of_games'] > 0)
										echo "<td>".$subrow['number_of_games']." games</td>";
									else if($subrow['number_of_games'] > 0)
										echo "<td>".$subrow['number_of_wins']." wins</td>";
									else if($subrow['number_of_games'] > 0)
										echo "<td>".$subrow['number_of_coaches']." coaches</td>";

									echo "<td>".$row['wins']." games</td>";

									if($row['active'] == 1)
									{
										echo "<td>Active</td>";
										
									}
									else if($row['active'] == 2)
									{
										echo "<td>Paused</td>";
										
									}
									else if($row['active'] == 3)
									{
										echo "<td>Admin reviewing</td>";
										
									}
									else if($row['active'] == 0)
									{
										echo "<td>Complete</td>";
										
									}

									$payment_result = mysql_query("SELECT SUM(amount) AS full_pay FROM payment WHERE identifier = '".$username."' AND booster_order = '".$subrow['id']."'") or die(mysql_error());
									$payment_row = mysql_fetch_array($payment_result);
									echo "<td>".$payment_row['full_pay']."</td>";
									echo "<td><a href='duo_order.php?id=".$subrow['id']."' class='btn btn-success btn-xs'>Details</a></td>";
									echo "</tr>";
									
								}
							}
						}
				?>
			   </tbody>
            </table>
         </div>
      </div>
   </div>
</div>    -->
    </div>
</div>

   </div>


<?php
	include("bottom.php");
?>
